package ui.activity;

import com.stuassist.ui.R;

import android.annotation.SuppressLint;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.graphics.Color;

public class MainActivity extends Activity  {
	private GridView mygrid ;  //课表显示
	private Button cur_takein;  //一键导入按钮
//	private Button cur_back=null;	返回按钮
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 加载视图
		super.setContentView(R.layout.activity_main);
		this.mygrid = (GridView) super.findViewById(R.id.mygrid);
		this.mygrid.setOnItemLongClickListener((OnItemLongClickListener) new MyLongClickListener());
		//获取相关控件的ID号
		this.cur_takein = (Button) findViewById(R.id.cur_takein);
		//一键导入按钮事件的响应
		this.cur_takein.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this,Take_in.class);
				startActivity(intent);
			}
		});
		GridView gridview = (GridView) findViewById(R.id.mygrid);
		gridview.setAdapter(new ImageAdpter(this));
	}
	
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			MainActivity.this.finish();
		}
		return false;
	}




	private class MyLongClickListener implements OnItemLongClickListener {
		@Override
		public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
				Dialog dialog = new AlertDialog.Builder(MainActivity.this)
				.setTitle("Message")
				.setMessage("�Ƿ����α�����?")
				.setIcon(R.drawable.pic4)
				.setPositiveButton("ȡ��",new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						
					}
				}).setNeutralButton("ȷ��",new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int which) {
						
					}
				}).create();
				dialog.show();
			return true;
		}
	}

	public class ImageAdpter extends BaseAdapter {
		private String[] texts = { "   ", "Mon", "Tue", "Wed", "Thu", "Fri",
				"Sat", "Sun" };

		private Context context;
		public ImageAdpter(Context context) {
			this.context = context;
		}

		@Override
		public int getCount() {
			return 8 * 13;
		}

		public Object getItem(int position) {
			return position;
		}

		@Override
		public long getItemId(int id) {
			return id;
		}

		@SuppressLint("NewApi") @Override
		public View getView(int position, View convertView, ViewGroup parent) {
			TextView tv = new TextView(context);
			tv.setText(position +texts[position]);
			tv.setTextSize(26);
			tv.setTextColor(Color.BLACK);  
			tv.setGravity(Gravity.CENTER);
			tv.setBackgroundColor(Color.WHITE);
			tv.setLayoutParams(new AbsListView.LayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)));
			return tv;
		}
	}
}
